home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 019a / splt_bat.zip / README < prev    next >
Text File  |  1993-03-26  |  13KB  |  440 lines

  1.                       TEST.BAT and EDIT.BAT README File
  2.  
  3. 1) TEST.BAT is a DOS batch routine to split the name of an input file into 
  4. three components: pathname, filename, and extension. It works because of the 
  5. FOR command's peculiar behaviour when a "/" is placed in front of the value in 
  6. the brackets, i.e. FOR %%a IN (/VALUE) DO. This command chops off the first
  7. letter in VALUE leaving ALUE. With this feature it is possible to "count" the
  8. length of a string, and chop off unwanted information. The batch, however, 
  9. cannot handle wildcards. If you are curious to see how it works search out the 
  10. REM's which come before ECHO statements and delete them, and then run the
  11. batch, you will see how the various components are generated. If you do not
  12. have a color monitor or do not have ANSI.SYS or an equivalent installed 
  13. remove the ANSI codes in the last ECHO statement, i.e. the "B"
  14.       One warning, even on a 486/33 machine, processing a file with a long 
  15. pathname can take a few seconds, it might be extremely slow on a slower
  16. machine.
  17.       Usage: Type TEST [pathname]\filename.ext. This batch file will not test 
  18. to see if you entered a filename which is valid by DOS standards, so if you
  19. wish to really test it make sure you enter a valid name (however, it is not
  20. necessary that you have a file with that name on your system).
  21.  
  22. @ECHO OFF
  23. REM If no file specified go to end 
  24. IF "%1"=="" GOTO End
  25.  
  26. REM Converts input to upper case. Not necessary but I used it to get the 
  27. REM output at the end in uppercase. This particular routine, except the line
  28. REM reading SET Pathname= should be removed. %UpCase% should then be be 
  29. REM changed to %1. It should also be changed everywhere else in the file.
  30. REM These places indicated by asterisks.
  31. SET OldPath=%Path%
  32. PATH=%1
  33. SET UpCase=%Path%
  34. SET Path=%OldPath%
  35. SET PathName=%UpCase%
  36. SET OldPath=
  37.  
  38. REM this routine determines if a path was attached to the file specified.
  39. REM If no path was indicated the batch then branches to SetExt.
  40. :PathSeek
  41. SET Prev=%PathName%
  42. FOR %%a IN (/%pathName%) DO SET PathName=%%a
  43. IF "\%PathName%"=="%Prev%" GOTO PathFound
  44. SET Count=%Count%x
  45. IF NOT "%PathName%"=="%Prev%" GOTO PathSeek
  46. REM *****************
  47. SET FileName=%UpCase%
  48. SET PathName=
  49. GOTO SetExt
  50.  
  51.  
  52. :PathFound
  53. REM **************** Little square box entered with Alt-254 on numeric keypad
  54. SET PathName=%UpCase%■
  55. SET Count=
  56. SET BackCount=
  57.  
  58. REM this routine determines the path's length.
  59. :PathLength
  60. SET Prev=%PathName%
  61. FOR %%a IN (/%PathName%) DO SET PathName=%%a 
  62. FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackSlash
  63. FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO FileSetup
  64. SET Count=%Count%x
  65. REM ECHO Value of PathName is %PathName%
  66. REM ECHO Value of Count %Count%
  67. GOTO PathLength
  68. :BackSlash
  69. REM ECHO VALUE OF PATHNAME IS %PathName%
  70. SET BackCount=%BackCount%x
  71. GOTO PathLength
  72.  
  73. :FileSetup
  74. REM *****************
  75. SET FileName=%UpCase%
  76. SET BkCount=
  77.  
  78. REM This routine gets the filename with its extension.
  79. :FileGet
  80. SET Prev=%FileName%
  81. FOR %%a IN (/%FileName%) DO SET FileName=%%a
  82. FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO Back
  83. REM ECHO Value of FileName is %FileName%
  84. GOTO FileGet
  85. :Back
  86. REM ECHO VALUE OF FileName IS %FileName%
  87. SET BkCount=%BkCount%x
  88. IF NOT "%BkCount%"=="%BackCount%" GOTO FileGet
  89.  
  90. SET TempFile=%FileName%■
  91. SET Count=
  92.  
  93. REM this routine gets the file and its extension's length.
  94. :FileLength
  95. SET Prev=%TempFile%
  96. FOR %%a IN (/%TempFile%) DO SET TempFile=%%a 
  97. FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO PathSetup
  98. SET Count=%Count%x
  99. REM ECHO Value of TempFile is %TempFile%
  100. REM ECHO Value of Count is %Count%
  101. GOTO FileLength
  102.  
  103.  
  104. :PathSetup
  105. SET Count=%Count%x
  106. REM *****************
  107. SET PathName=%UpCase%
  108. SET BkCount=
  109. SET File=
  110. SET TempFile=
  111.  
  112.  
  113. REM the following routines will get the files pathname.
  114. :PathGet1
  115. SET Prev=%PathName%
  116. FOR %%a IN (/%PathName%) DO SET PathName=%%a
  117. FOR %%a IN (/%Prev%) DO IF "%%a%PathName%"=="%Prev%" SET
  118. PathName=%PathName%%%a
  119. FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackAgain
  120. REM ECHO Value of PathName is %PathName%
  121. GOTO PathGet1
  122. :BackAgain
  123. REM ECHO VALUE OF PATHNAME IS %PathName%
  124. SET BkCount=%BkCount%x
  125. IF NOT "%BkCount%"=="%BackCount%" GOTO PathGet1
  126.  
  127. SET Counter=
  128.  
  129. :PathGet2
  130. FOR %%a IN (/%PathName%) DO SET PathName=%%a
  131. SET Counter=%Counter%x
  132. REM ECHO VALUE OF PATHNAME IS %PathName%
  133. IF NOT "%Counter%"=="%Count%" GOTO PathGet2
  134.  
  135. SET Counter=
  136. SET Count=
  137. SET BkCount=
  138. SET BackCount=
  139.  
  140. :SetExt
  141.  
  142. SET Ext=%FileName%
  143.  
  144. REM this routine checks to see if the specified file had an extension.
  145. REM This comes from Prof. Timo Salmi's collection of batch files TSBAT*.ZIP
  146. REM a good primer for batch programming.
  147. :ExtCheck
  148. SET Prev=%Ext%
  149. FOR %%a IN (/%Ext%) DO SET Ext=%%a
  150. IF ".%Ext%"=="%Prev%" GOTO ExtFound
  151. REM ECHO Value of Ext is %Ext%
  152. SET Count=%Count%x
  153. IF NOT "%Ext%"=="%Prev%" GOTO ExtCheck
  154. SET Name=%FileName%
  155. SET Ext=
  156. GOTO NoExt
  157.  
  158. :ExtFound
  159. SET Prev=
  160. SET Len=
  161. SET NewExt=%Ext%■
  162.  
  163. REM this routine determines the length of the extension.
  164. :FindLen
  165. FOR %%a IN (/%NewExt%) DO SET NewExt=%%a
  166. SET Len=%Len%x
  167. IF NOT "%NewExt%"=="■" GOTO FindLen
  168.  
  169. SET NewExt=
  170. SET Name=%FileName%
  171. SET NewCount=
  172.  
  173. REM the following routines chop off the extension to get the files's name.
  174. :ChopExt 
  175. SET Prev=%Name%
  176. FOR %%a IN (/%Name%) DO SET Name=%%a
  177. FOR %%a IN (/%Prev%) DO IF "%%a%Name%"=="%Prev%" SET Name=%Name%%%a
  178. REM ECHO Value of Name is %Name%
  179. SET NewCount=%NewCount%x
  180. IF NOT "%Count%"=="%NewCount%" GOTO ChopExt
  181.  
  182. SET NewCount=
  183. SET NewLen=
  184.  
  185. :GetName
  186. SET Prev=%Name%
  187. FOR %%a IN (/%Name%) DO SET Name=%%a
  188. REM ECHO Value of Name is %Name%
  189. SET NewLen=%NewLen%x
  190. IF NOT "%NewLen%"=="%Len%x" GOTO GetName
  191. SET NewLen=
  192. SET Len=
  193.  
  194. :NoExt
  195. SET FileName=
  196. SET Count=
  197. SET Prev=
  198.  
  199. IF NOT "%PathName%"=="" SET PathState=full Path Name is "%PathName%",
  200. IF NOT "%Name%"=="" SET NameState=Name is "%Name%"
  201. IF NOT "%Ext%"=="" SET ExtState=, and Extension is "%Ext%"
  202.  
  203.  
  204. cls
  205. ECHO B"%UpCase%"'s %PathState% %NameState%%ExtState% 
  206. SET PathState=
  207. SET NameState=
  208. SET ExtState=
  209.  
  210. :End
  211.  
  212. 2) EDIT.BAT is a batch application which uses the TEST.BAT routine. DOS 5.0's
  213. EDIT is a much better editor than EDLIN but it does not create a backup of a
  214. file that you edit. In this regard EDLIN has the following features, if you 
  215. make changes to an existing file it creates a .BAK file, if you open a file
  216. but do not make any changes it does not create a backup file. If you load a 
  217. file with the name FILE.EXT and a FILE.BAK backup file already exists in the 
  218. current directory EDIT.BAT will not destroy FILE.BAK if you do not make any 
  219. changes to FILE.EXT. EDLIN also creates its backup files in the directory 
  220. where the edited files reside. EDIT.BAT will do all of these things, with the 
  221. exception of the last. It creates its .BAK files in the current directory. 
  222. This, however, can easily be changed by modifying the routine RenBak which 
  223. creates the .BAK file (See REM statement for details).
  224.       This batch file when determining if a file has been changed creates some
  225. temporary files (in the routine labelled FilComp). I direct them to my ramdisk
  226. "E:", you should replace this path with the directory in which you wish to 
  227. have them created. If the batch terminates normally it will delete all its
  228. temporary files, however, if it should terminate abnormally having the 
  229. temporary files on a ramdisk means that they will be deleted upon next reboot, 
  230. not leaving any extra files on disk.
  231.       This batch file also uses ANSI codes so if you do not have a color 
  232. monitor or do not have ANSI.SYS or an equivalent loaded you should remove the 
  233. codes i.e. 23H and  on line 10.
  234.       This batch file assumes that EDIT.COM is on C drive in \DOS directory. 
  235. If you should have yours in another directory you will have to modify the path
  236. in the routine labelled LoadEdit.
  237.       Usage: EDIT [pathname]\filename.ext
  238.  
  239. @ECHO OFF
  240. IF "%1"=="" GOTO LoadEdit
  241. IF NO EXIST %1 GOTO LoadEdit
  242. SET PathName=%1
  243. CLS
  244. SET OldPath=%Path%
  245. PATH=%1
  246. SET UpCase=%Path%
  247. SET Path=%OldPath%
  248. ECHO 23HPlease wait; loading %UpCase%
  249. SET OldPath=
  250. SET UpCase=
  251. :PathSeek
  252. SET Prev=%PathName%
  253. FOR %%a IN (/%pathName%) DO SET PathName=%%a
  254. IF "\%PathName%"=="%Prev%" GOTO PathFound
  255. SET Count=%Count%x
  256. IF NOT "%PathName%"=="%Prev%" GOTO PathSeek
  257. SET FileName=%1
  258. SET PathName=
  259. GOTO SetExt
  260.  
  261.  
  262. :PathFound
  263. SET PathName=%1■
  264. SET Count=
  265. SET BackCount=
  266.  
  267. :PathLength
  268. SET Prev=%PathName%
  269. FOR %%a IN (/%PathName%) DO SET PathName=%%a 
  270. FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackSlash
  271. FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO FileSetup
  272. SET Count=%Count%x
  273. REM ECHO Value of PathName is %PathName%
  274. REM ECHO Value of Count %Count%
  275. GOTO PathLength
  276. :BackSlash
  277. REM ECHO VALUE OF PATHNAME IS %PathName%
  278. SET BackCount=%BackCount%x
  279. GOTO PathLength
  280.  
  281. :FileSetup
  282. SET FileName=%1
  283. SET BkCount=
  284.  
  285. :FileGet
  286. SET Prev=%FileName%
  287. FOR %%a IN (/%FileName%) DO SET FileName=%%a
  288. FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO Back
  289. REM ECHO Value of FileName is %FileName%
  290. GOTO FileGet
  291. :Back
  292. REM ECHO VALUE OF FileName IS %FileName%
  293. SET BkCount=%BkCount%x
  294. IF NOT "%BkCount%"=="%BackCount%" GOTO FileGet
  295.  
  296. SET TempFile=%FileName%■
  297. SET Count=
  298. :FileLength
  299. SET Prev=%TempFile%
  300. FOR %%a IN (/%TempFile%) DO SET TempFile=%%a 
  301. FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO PathSetup
  302. SET Count=%Count%x
  303. REM ECHO Value of TempFile is %TempFile%
  304. REM ECHO Value of Count is %Count%
  305. GOTO FileLength
  306.  
  307.  
  308. :PathSetup
  309. SET Count=%Count%x
  310. SET PathName=%1
  311. SET BkCount=
  312. SET File=
  313. SET TempFile=
  314.  
  315.  
  316. :PathGet1
  317. SET Prev=%PathName%
  318. FOR %%a IN (/%PathName%) DO SET PathName=%%a
  319. FOR %%a IN (/%Prev%) DO IF "%%a%PathName%"=="%Prev%" SET
  320. PathName=%PathName%%%a
  321. FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackAgain
  322. REM ECHO Value of PathName is %PathName%
  323. GOTO PathGet1
  324. :BackAgain
  325. REM ECHO VALUE OF PATHNAME IS %PathName%
  326. SET BkCount=%BkCount%x
  327. IF NOT "%BkCount%"=="%BackCount%" GOTO PathGet1
  328.  
  329. SET Counter=
  330.  
  331. :PathGet2
  332. FOR %%a IN (/%PathName%) DO SET PathName=%%a
  333. SET Counter=%Counter%x
  334. REM ECHO VALUE OF PATHNAME IS %PathName%
  335. IF NOT "%Counter%"=="%Count%" GOTO PathGet2
  336.  
  337. SET Counter=
  338. SET Count=
  339. SET BkCount=
  340. SET BackCount=
  341.  
  342. :SetExt
  343.  
  344. SET Ext=%FileName%
  345.  
  346. :ExtCheck
  347. SET Prev=%Ext%
  348. FOR %%a IN (/%Ext%) DO SET Ext=%%a
  349. IF ".%Ext%"=="%Prev%" GOTO ExtFound
  350. REM ECHO Value of Ext is %Ext%
  351. SET Count=%Count%x
  352. IF NOT "%Ext%"=="%Prev%" GOTO ExtCheck
  353. SET Name=%FileName%
  354. SET Ext=
  355. GOTO NoExt
  356.  
  357. :ExtFound
  358. SET Prev=
  359. SET Len=
  360. SET NewExt=%Ext%■
  361.  
  362. :FindLen
  363. FOR %%a IN (/%NewExt%) DO SET NewExt=%%a
  364. SET Len=%Len%x
  365. IF NOT "%NewExt%"=="■" GOTO FindLen
  366.  
  367. SET NewExt=
  368. SET Name=%FileName%
  369. SET NewCount=
  370.  
  371. :ChopExt 
  372. SET Prev=%Name%
  373. FOR %%a IN (/%Name%) DO SET Name=%%a
  374. FOR %%a IN (/%Prev%) DO IF "%%a%Name%"=="%Prev%" SET Name=%Name%%%a
  375. REM ECHO Value of Name is %Name%
  376. SET NewCount=%NewCount%x
  377. IF NOT "%Count%"=="%NewCount%" GOTO ChopExt
  378.  
  379. SET NewCount=
  380. SET NewLen=
  381.  
  382. :GetName
  383. SET Prev=%Name%
  384. FOR %%a IN (/%Name%) DO SET Name=%%a
  385. REM ECHO Value of Name is %Name%
  386. SET NewLen=%NewLen%x
  387. IF NOT "%NewLen%"=="%Len%x" GOTO GetName
  388. SET NewLen=
  389. SET Len=
  390.  
  391. :NoExt
  392. SET FileName=
  393. SET Count=
  394. SET Prev=
  395.  
  396. :CopyTemp
  397. COPY %1 %Name%.$$$>NUL
  398. SET Exists=1
  399.  
  400. :LoadEdit
  401. C:\DOS\EDIT %1
  402. IF "%1"=="" GOTO End
  403. IF "%Exists%"=="" GOTO End
  404.  
  405. :FilComp
  406. FC %1 %Name%.$$$>E:\TEMP$$$$.$$$
  407. FIND /N "FC: no differences encountered" < E:\TEMP$$$$.$$$ > E:\COMP$$$.$$$
  408. IF EXIST E:\TEMP$$$$.$$$ ERASE E:\TEMP$$$$.$$$
  409. COPY E:\COMP$$$.$$$ E:\COMP$$$$.$$$ > NUL
  410. IF EXIST E:\COMP$$$$.$$$ ERASE E:\COMP$$$.$$$
  411.  
  412. IF NOT EXIST E:\COMP$$$$.$$$ GOTO RenBak
  413. IF EXIST %Name%.$$$ ERASE %Name%.$$$
  414. GOTO End
  415.  
  416. :RenBak
  417. IF EXIST %Name%.BAK ERASE %Name%.BAK
  418. IF EXIST %Name%.$$$ REN %Name%.$$$ %Name%.BAK
  419. IF EXIST E:\COMP$$$$.$$$ ERASE E:\COMP$$$$.$$$
  420. REM If you should wish to have your backup files created in the directory
  421. REM where the edited file resides change remove the REM's in front of the
  422. REM of the next few lines and delete or REM out the three lines above begin-
  423. REM ning with IF EXIST
  424. REM COPY %Name%.$$$ %PathName%%Name%.BAK
  425. REM ERASE %NAME%.$$$
  426. COPY
  427. :End
  428. SET Pathname=
  429. SET Name=
  430. SET Ext=
  431. SET Exists=
  432.  
  433. Hope you enjoy these two batch files. If you have any questions and comments
  434. you can reach me at:
  435. Daniel Marier
  436. 262A Vaughan Rd
  437. Toronto, Ontario
  438. Canada  M6C 2N1
  439. until mid-May '93.
  440.